

//
//  UILabel+CPJLabel.m
//  成品家
//
//  Created by YYY on 2017/3/7.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "UILabel+CPJLabel.h"

@implementation UILabel (CPJLabel)

//普通label
-(void)setTextStr:(NSString *)textStr fontSize:(CGFloat)fontSize textColor:(UIColor *)textColor
{
    self.text = [NSString stringWithFormat:@"%@",textStr];
    self.font = [UIFont systemFontOfSize:fontSize];
    self.textColor = textColor;
}

//UILabel内容宽、高自适应
-(CGSize)boundingRectWithSize:(CGSize)size
{
    NSDictionary *attribute = @{NSFontAttributeName : self.font};
    CGSize retSize = [self.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine attributes:attribute context:nil].size;
    return retSize;
}

//UILabel字体颜色属性设置
-(NSMutableAttributedString *)attributedSetting:(NSString *)textString length:(NSInteger)length location:(NSInteger)location valueColor:(UIColor *)valueColor
{
    NSRange range = NSMakeRange(location,length);
    NSMutableAttributedString *state = [[NSMutableAttributedString alloc]initWithString:textString];
    [state addAttribute:NSForegroundColorAttributeName value:valueColor range:range];
    return state;
}

//UILabel字体大小属性设置
-(NSMutableAttributedString *)attributedSetting:(NSString *)textString length:(NSInteger)length location:(NSInteger)location valueFont:(CGFloat)valueFont
{
    NSRange range = NSMakeRange(location,length);
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:textString];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:valueFont] range:range];
    return attributedString;
}

//UILabel调整行间距属性设置
-(NSMutableAttributedString *)attributedSetting:(NSString *)textString lineSpacing:(CGFloat)lineSpacing location:(NSInteger)location length:(NSInteger)length
{
    NSRange range = NSMakeRange(location,length);
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:textString];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:lineSpacing];
    
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
    return attributedString;
}

//UILabel调整字体大小、字体颜色属性设置
-(NSMutableAttributedString *)attributedSetting:(NSString *)textString valueFont:(CGFloat)valueFont valueColor:(UIColor *)valueColor location:(NSInteger)location length:(NSInteger)length
{
    NSRange range = NSMakeRange(location,length);
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:textString];
    [attributedString addAttribute:NSForegroundColorAttributeName value:valueColor range:range];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:valueFont] range:range];
    return attributedString;
}

@end
